package com.gzxw.mogublog.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gzxw.mogublog.admin.annotation.OperationLogger.OperationLogger;
import com.gzxw.mogublog.commons.entity.Admin;
import com.gzxw.mogublog.commons.entity.Role;
import com.gzxw.mogublog.utils.R;
import com.gzxw.mogublog.xo.service.RoleService;
import com.gzxw.mogublog.xo.vo.CategoryMenuVO;
import com.gzxw.mogublog.xo.vo.RoleVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @PostMapping("/getList")
    public R getList(@RequestBody RoleVO roleVO) {

        IPage<Role> pageList = roleService.getPageList(roleVO);
        Map<String, Object> result = new HashMap<>();
        List<Role> records = pageList.getRecords();
        long total = pageList.getTotal();
        long size = pageList.getSize();
        long current = pageList.getCurrent();
        result.put("records", records);
        result.put("total", total);
        result.put("size", size);
        result.put("current", current);
        return R.success("200", result);

    }


    @OperationLogger("增加角色")
    @PostMapping("/add")
    public R add(@RequestBody RoleVO roleVO) {

       String message =  roleService.addRole(roleVO);

       return R.success("200",message);
    }

    @OperationLogger("编辑角色")
    @PostMapping("/edit")
    public R update(@RequestBody RoleVO roleVO) {
       String message =  roleService.editRole(roleVO);

       return R.success("200",message);

    }

    @OperationLogger("删除角色")
    @PostMapping("/delete")
    public R delete(@RequestBody RoleVO roleVO) {

       String message = roleService.deleteRole(roleVO);

        return R.success("200",message);
    }



}
